package cn.tedu.boot21.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class HelloController {
    //http://localhost:8080/hello
    @RequestMapping("/hello")
    public void hello(HttpServletRequest request,HttpServletResponse response) throws IOException {
        String info = request.getParameter("info");
        System.out.println("方法触发了!");
        //设置响应类型
        response.setContentType("text/html;charset=utf-8");
        //得到输出对象    异常抛出
        PrintWriter pw = response.getWriter();
        //输出数据
        pw.println("服务器接收到了您的请求! <h1>你瞅啥?</h1>"+info);
        //关闭资源
        pw.close();
    }

    @RequestMapping("/hello2")
    @ResponseBody//通过返回值的方式给客户端响应数据
    public String hello2(){
        return "服务器接收到了您的请求,第二种方式成功!";
    }
}
